import request from "@/utils/request";
import type { RegionType } from "./type";
const REGION_BASE_URL = "/api/v1/region";
export const getRegionList = () => {
  return request<any, RegionType[]>({
    url: `${REGION_BASE_URL}`,
    method: "get",
  });
};

export const getAllRegion = () => {
  return request<any, RegionType[]>({
    url: `${REGION_BASE_URL}/getAllRegion`,
    method: "get",
  });
};
export const getRegionByLevelAndParentId = (level?: string, parentId?: string) => {
  return request<any, RegionType[]>({
    url: `${REGION_BASE_URL}/getByLevelAndParentId`,
    method: "post",
    data: { level, parentId },
  });
};

export const getRegionById = (id: string) => {
  return request<any, RegionType>({
    url: `${REGION_BASE_URL}/getRegionById`,
    method: "get",
    params: { id },
  });
};

export const saveAndUpdateRegion = (params: Partial<RegionType>) => {
  return request<any, boolean>({
    url: `${REGION_BASE_URL}`,
    method: params?.id ? "put" : "post",
    data: params,
  });
};

export const deleteRegionById = (id: string) => {
  return request<any, boolean>({
    url: `${REGION_BASE_URL}`,
    method: "delete",
    params: { id },
  });
};
